package hot;

/**
 * @author lakersUp
 * @Classname   搜索旋转排序数组
 * @Description     根据有序的一半,来确定二分的区间
 * @Date 2022/3/9 14:30
 * @Version 1.0
 */
public class Hot33search {
    public int search(int[] nums, int target) {
        int right=nums.length-1;
        int left=0;
        while(left<=right){
            int mid=(left+right)/2;
            if(nums[mid]==target){
                return mid;
            }
            if(nums[0]<=nums[mid]){
                if(nums[0]<=target && nums[mid]>target){
                    right=mid-1;
                }else {
                    left=mid+1;
                }
            }else{
                if(nums[mid]<target && target<=nums[nums.length-1]){
                    left=mid+1;
                }else {
                    right=mid-1;
                }
            }
        }
        return -1;
    }
}
